/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useRef } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import ProTableExtend from '@base/components/ProTableExtend';
import { ColumnItem, useCreateColumns } from '@/components/_pages/4gPrinterVip/columns';
import { deleteVipPrinter, getVipPrinter, revokeVipPrinter } from '@/services/4gPrinterVip';
import Add from '@/components/_pages/4gPrinterVip/add';
import { ActionType } from '@ant-design/pro-table';

const Page4gPrinterVip: React.FC = () => {
  const tableRef = useRef<ActionType>();

  const handleOperate = (key: string, data: ColumnItem) => {
    const req = { id: data.id };
    if (key === 'revoke') {
      return revokeVipPrinter(req);
    }
    if (key === 'delete') {
      return deleteVipPrinter(req);
    }
    return Promise.resolve();
  };

  const columns = useCreateColumns();

  const handleSuccess = () => tableRef.current?.reload();

  return (
    <PageContainer>
      <ProTableExtend<ColumnItem, any, 'text'>
        actionRef={tableRef}
        options={{
          setting: {
            listsHeight: 400,
          },
        }}
        onOperate={handleOperate}
        columns={columns}
        request={getVipPrinter}
        toolBarRender={() => [<Add onSuccess={handleSuccess} />]}
        search={{}}
      />
    </PageContainer>
  );
};

export default Page4gPrinterVip;
